#include"MemoryPool.h"
#include<vector>
#include<thread>
void func() {
	MemoryPool* instance = MemoryPool::getLocalInstance();
	std::vector<char*>datas;
	for (int i = 0; i < 10; ++i) {
		char* data = static_cast<char*>(instance->getMemory(1000));
		data[0] = '1';
		data[100] = '2';
		datas.push_back(data);
	}
	for (int i = 0; i < 5; ++i) {
		instance->freeMemory(datas[i]);
	}
	for (int i = 0; i < 10; ++i) {
		char* data = static_cast<char*>(instance->getMemory(1000));
		data[0] = '1';
		data[100] = '2';
		datas.push_back(data);
	}
	for (int i = 5; i < 10; ++i) {
		instance->freeMemory(datas[i]);
	}
	for (int i = 0; i < 10; ++i) {
		char* data = static_cast<char*>(instance->getMemory(1000));
		data[0] = '1';
		data[100] = '2';
		datas.push_back(data);
	}
	for (int i = 10; i < datas.size(); ++i) {
		instance->freeMemory(datas[i]);
	}
	
}

int main() {
	std::vector<std::thread> threads;
	for (int i = 0; i < 10; ++i) {
		threads.emplace_back(func);
	}
	for (int i = 0; i < 10; ++i) {
		threads[i].join();
	}
}